package com.example.kakaotalk;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends Activity {

	MyItemSendView sendView;
	ListView listView;
	EditText addTextView;
	MyAdapter mAdapter;
	MyData[] mData = { new MyData("aaa"), new MyData("bbb"), new MyData("ccc") };
	ArrayList<MyData> mList = new ArrayList<MyData>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		listView = (ListView) findViewById(R.id.myListView);
		listView.setDivider(null);
		listView.setFocusable(false);
		
		addTextView = (EditText) findViewById(R.id.addText);
		setData();
		
		mAdapter = new MyAdapter(this,mList);
		listView.setAdapter(mAdapter);
		Button btn = (Button) findViewById(R.id.addButton);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String text = addTextView.getText().toString();
				if(text!=null && !text.equals("")){
					mAdapter.add(new MyData(text,true));
					addTextView.setText("");
				}
			}
		});
	}
	
	private void setData() {
		for (MyData str : mData) {
			mList.add(str);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
